<template>
	<view class="mainbgc">
		<!-- tab栏： -->
		<view class="topTab tabBg ffffff">
			<u-tabs :list="tabList" @click="changetab" lineColor="#00D4E2"
				itemStyle="height:88rpx; padding: 0rpx 55rpx 0rpx 55rpx;" lineWidth="30"></u-tabs>
		</view>
		<!-- 门票列表： -->
		<view class="ticket-list mainpadding" v-show="show">
			<view class="flexcenter1" v-if="!list.data.length">
				<view class="placeholderimg" style="margin-top: 300rpx;">
					<image src="../../static/images/bg-icons/placeholderimg.png" mode=""></image>
				</view>
				<view class="zanwushuju">暂无数据~</view>
			</view>
			<!-- 门票项： -->
			<view class="ticket-item mainpadding ffffff border-r1" v-for="item in list.data" :key="item.id"
				@click="toTicketDetails(item.id)">
				<view class="title flexleft2">
					<view class="add">{{item.tour.name}}</view>
					<view class="tStatus">{{item.checkinfo_text}}</view>
				</view>

				<view class="ticket-details margin-top" v-for="ite in item.goods" :key="ite.id">
					<view class="img">
						<image :src="ite.images_text" mode=""></image>
					</view>
					<view class="details">
						<view class="name">{{ite.tour_ticket_name}}</view>
						<view class="pAc flexleft2">
							<text class="tMoney">￥{{ite.tour_price}}</text>
							<text class="tCount">x{{ite.total_num}}</text>
						</view>
					</view>
				</view>
				<!-- 提示： -->
				<view class="tips">共计{{item.people_num}}张门票 合计￥<text class="tMoney">{{item.total_price}}</text></view>
				<!-- 按钮： -->
				<view class="btn-box flexleft margin-top">
					<view class="quxiao" v-show="item.checkinfo==1||item.checkinfo==2"  @click.stop="cancelorder(item.id)">取消</view>
					<view class="zhifu" v-show="item.checkinfo==1"  @click.stop="atoncepay(item)">立即支付</view>
					<view class="shanchu"  v-show="item.checkinfo==3||item.checkinfo=='-1'" @click.stop="delorder(item.id)">删除订单</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tabList: [{
						name: '全部'
					},
					{
						name: '待付款'
					},
					{
						name: '待核销'
					},
					{
						name: '已完成'
					},
				],
				currenttab: 0, //状态：:0=全部，1=待付款，2=待核销，3=已完成
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				states: 0,
				
				show:false,
			}
		},
		onLoad(){
			this.init()
		},
		onShow() {
			// this.init()
		},
		methods: {
			// 删除订单
			delorder(id) {
				httpRequest.modal('', '确认删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('api/tourorder/delOrder', 'POST', {
							id
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			// 取消订单
			cancelorder(id) {
				httpRequest.modal('', '确认取消当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('api/tourorder/cancelOrder', 'POST', {
							id
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			// 立即支付
			atoncepay(item){
				let data = {
					id:item.id,
					pay_price:item.pay_price,
					allscore:item.allow_score
				}
				uni.navigateTo({
					url:'/pages/scenic/lijizf?msg=' + encodeURIComponent(JSON.stringify(data))
				})
			},
			init(isPage, page) {
				let _this = this;
				httpRequest.request('api/tourorder/myOrder', 'GET', {
					page: page || 1,
					limit: _this.limit,
					status: this.states,
				}, false, false, false).then(res => {
					this.show=true
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					this.show=true
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			changetab(item) {
				if(item.index==3){
					this.states=4
				}else{
				  this.states = item.index
				}
				this.init()
			},
			toTicketDetails(id) {
				uni.navigateTo({
					url: '/pages/my/menpiaoxiangqing?id='+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.ticket-order{
	}
	.add {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.tStatus {
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.img {
		width: 124rpx;
		height: 124rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.ticket-details {
		display: flex;
		justify-content: space-between;
		border-bottom: 2rpx solid #fafafa;
	}

	.details {
		flex: 1;
		margin-left: 30rpx;
		margin-bottom: 30rpx;
	}

	.pAc {
		margin-top: 42rpx;
	}

	.tMoney {
		font-size: 30rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: #FF5C00;
	}

	.tCount {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.tips {
		padding: 30rpx 0;
		text-align: right;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF5C00;
	}

	.btn-box {
		float: right;
	}

	.quxiao {
		padding: 8rpx 50rpx;
		border: 2rpx solid #666666;
		border-radius: 30rpx;
	}

	.zhifu {
		padding: 8rpx 30rpx;
		border-radius: 30rpx;
		margin-left: 25rpx;
		background-color: #00D2E1;
		color: #fff;
		border: 2rpx solid #00D2E1;
	}

	.shanchu {
		padding: 8rpx 30rpx;
		border: 2rpx solid #666666;
		border-radius: 30rpx;
	}

	.ticket-item {
		overflow: hidden;
		margin-bottom: 30rpx;
	}
</style>
